/**
 * @file string.cc
 * @author Bono.ASUN.TamGitsun (gitsun.tam@outlook.com)
 * @brief 
 * @version 0.1
 * @date 2022-02-07
 * 
 * @copyright Copyright (c) 2022
 * 
 */


#include "string.hh"
#include <sstream>


namespace TGS::utils {


std::vector<std::string> string_split(const std::string & str, const std::string & token)
{
    std::vector<std::string> results;
    string_split(str, token, results);
    return results;
}

void string_split(const std::string & str, const std::string & token, std::vector<std::string> & results)
{
    const char * str_ = str.c_str();
    const char * token_ = token.c_str();
    size_t begin = 0;
    size_t count = 0;
    for (size_t i = 0; i < str.length() - token.length();)
    {
        if (0 == strncmp(str_ + i, token_, token.length()))
        {
            results.push_back(str.substr(begin, count));
            i += token.length();
            begin = i;
            count = 0;
            continue;
        }
        ++i;
        ++count;
    }
    if (count > 0)
    {
        results.push_back(str.substr(begin));
    }
}


}
